﻿#include "UWidgetRestorer.h"

UWidgetRestorer::UWidgetRestorer(QWidget* widget)
	: m_widget(widget)
{
	if (!m_widget)
		return;
	m_originalParent = m_widget->parentWidget();
	m_originalGeometry = m_widget->geometry();

}

void UWidgetRestorer::restore()
{
	if (!m_widget || !m_originalParent)
		return;
	// 临时脱离原父窗口
	m_widget->setParent(nullptr);
	// 设置新的父窗口
	m_widget->setParent(m_originalParent);
	m_widget->setGeometry(m_originalGeometry);
	m_widget->hide();
}
